export * from './text.js'
//export * from './validator.js'
export function toast(msg) {
	uni.showToast({
		title: msg,
		icon: 'none',
		duration: 2000
	})
}
export const testUrl = 'http://192.168.1.21/api/v1'
export const baseUrl = 'https://xiaojia.jianli33.com/'
export const logintype = 'wx' // wx 微信 msg 短信
export function getQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
    }
    return '';
}

export function setNavigation()//如果用户有指定导航page
{
	let page = this.$util.getQueryVariable('page');
	let uri = (page == 1 ? '/pages/shopping-index/shopping-index': 
			   page == 2 ? '/pages/person/person': 
			   page == 3 ? '/pages/live/live-list': '/pages/Index/Index')
	uni.switchTab({
		url: uri
	})	
}

export function setUserInfo() //设置用户登录
{
	console.log('set user info')
	this.$api.getUserInfo().then(res => {
		this.$store.commit('setUserInfo',res.data);
		let sfm =  this.$util.getQueryVariable('sfm')
		this.$api.bindMaster({sfm});
		if(!/^1\d{10}/.test(res.data.mobile)){
			uni.navigateTo({
				url:'/pages/login/bind-mobile'
			})
			return
		}
		this.setNavigation()
	})
}

export function dateFormat(fmt, timestamp) {
    let ret,date;
	date = new Date(parseInt(timestamp))
    const opt = {
        "Y+": date.getFullYear().toString(),        // 年
        "m+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "H+": date.getHours().toString(),           // 时
        "M+": date.getMinutes().toString(),         // 分
        "S+": date.getSeconds().toString(),         // 秒
        "s+": date.getMilliseconds().toString()          // 毫秒
        // 有其他格式化字符需求可以继续添加，必须转化成字符串
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}